<!--
 * @Description: 订单管理模块
 * @Author: pinus
 * @Email: pinus0716@163.com
 * @Git: https://gitee.com/xyf97
 * @Date: 2021-10-02 18:49:05
 * @LastEditTime: 2021-10-02 20:52:00
-->
<template>
  <div class="order-container">
    <!--  头部面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/wlecome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加商品</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 内容card -->
    <el-card>
      <!-- 搜索栏与添加栏 -->
      <el-row :gutter="20">
        <el-col :span="10">
          <el-input placeholder="请输入内容"
            clearable
            v-model="getParams.query"
            @clear="clearSearch">
            <el-button slot="append"
              icon="el-icon-search"
              @click="getInitOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table :data="orderList"
        border>
        <el-table-column type="index"
          label="#"
          align="center"> </el-table-column>
        <el-table-column prop="order_number"
          width="300"
          label="订单编号"
          align="center"> </el-table-column>
        <el-table-column prop="order_price"
          width="80"
          label="价格"
          align="center"> </el-table-column>
        <el-table-column width="80"
          label="是否付款"
          align="center">
          <template slot-scope="scope">
            <el-tag type="success"
              v-if="scope.row.pay_status == 1">已付款</el-tag>
            <el-tag type="warning"
              v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column width="100"
          label="是否发货"
          align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.is_send == '是'">已发货</el-tag>
            <el-tag type="danger"
              v-else>未发货</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center"
          label="下单时间">
          <template slot-scope="scope">
            <!-- 调用过滤器规范时间格式 -->
            {{ scope.row.create_time | dateFormate }}
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作"
          width="210"
          align="center">
          <template>
            <!-- 编辑按钮 -->
            <el-button size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="targrtDialogVisible = true">编辑</el-button>
            <!-- 查看物流信息按钮 -->
            <el-button size="mini"
              type="success"
              icon="el-icon-position"
              @click="getKuaiDi">物流</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 换页区域 -->
      <el-pagination layout="total, sizes, prev, pager, next, jumper"
        :current-page="getParams.pagenum"
        :page-sizes="[10, 20, 30]"
        :page-size="getParams.pagesize"
        :total="totalOrders"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"> </el-pagination>
    </el-card>

    <!-- 物流对话框 -->
    <el-dialog title="物流信息"
      :visible.sync="kuaiDialogVisible">
      <el-timeline :reverse="false">
        <el-timeline-item v-for="(activity, index) in kuaidiList"
          :key="index"
          :color="index === 0 ? '#0BBD87' : '' "
          :icon="index === 0 ? 'el-icon-location-information' : '' "
          :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>

    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址"
      :visible.sync="targrtDialogVisible">
      <el-form ref="targrtFormRef"
        :model="targrtForm"
        label-width="auto"
        :rules="targrtFormRules"
        status-icon>
        <el-form-item label="省/市"
          prop="cities">

          <el-cascader v-model="targrtForm.cities"
            :options="cityData"
            :props="cascaderProps"
            @change="handelChange"
            clearable
            size="small"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址"
          prop="detailed">
          <el-input v-model="targrtForm.detailed"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部操控区域 -->
      <!-- <div slot="footer">
          <el-button @click="closeEditGood">取 消</el-button>
          <el-button type="primary"
            @click="submitEdit">确 定</el-button>
        </div> -->
    </el-dialog>
  </div>
</template>

<script>
import cityData from '@/assets/js/citydata.js'

export default {
  name: 'Order',
  data() {
    return {
      orderList: [],
      getParams: {
        query: '',
        pagenum: 3,
        pagesize: 10,
        // 以下可以为空
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '', // ['个人','公司']
        order_fapiao_company: '',
        order_fapiao_content: '',
        consignee_addr: ''
      },
      totalOrders: 0,
      // 物流
      kuaiDialogVisible: false,
      kuaidiList: [],
      // target
      targrtDialogVisible: false,
      targrtForm: {
        cities: [],
        detailed: []
      },
      targrtFormRules: {
        cities: [{ required: true, message: '请选择城市', trigger: 'blur' }],
        detailed: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
      },
      cascaderProps: {
        expandTrigger: 'hover'
      },
      cityData
    }
  },
  created() {
    this.getInitOrderList()
  },
  methods: {
    handelChange() {
      console.log(this.targrtForm.cities)
    },
    async getInitOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: {
          query: this.getParams.query,
          pagenum: this.getParams.pagenum,
          pagesize: this.getParams.pagesize
        }
      })

      // console.log(this.getParams)
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      this.orderList = res.data.goods
      this.getParams.pagenum = parseInt(res.data.pagenum)
      this.totalOrders = res.data.total
    },
    // 清空搜索框
    clearSearch() {
      this.getParams.query = ''
      this.getInitOrderList()
    },
    // 改变一页展示数目
    handleSizeChange(val) {
      this.getParams.pagesize = val
      this.getInitOrderList()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.getParams.pagenum = val
      this.getInitOrderList()
    },
    // 查看物流信息
    async getKuaiDi() {
      const id = '1106975712662'
      const { data: res } = await this.$http.get(`/kuaidi/${id}`)

      // console.log(this.getParams)
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }

      this.kuaidiList = res.data
      this.kuaiDialogVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.is-send-icon {
  font-size: 30px;
  color: #8c939d;

  text-align: center;
}
</style>
